use actix_cors::Cors;
use actix_web::http::header;

pub struct CorsConfig;

impl CorsConfig {
    pub fn cors_config() -> Cors {
        Cors::default()
            // .allowed_origin("http://127.0.0.1")
            // .allowed_origin_fn(|origin, _req_head| {
            //     origin.as_bytes().starts_with(b"http://127.0.0.1")
            // })

            // set allowed methods list
            .allowed_methods(vec!["GET", "POST", "DELETE", "PUT", "OPTION"])

            // set allowed request header list
            .allowed_headers(&[header::AUTHORIZATION, header::ACCEPT])

            // add header to allowed list
            .allowed_header(header::CONTENT_TYPE)

            // set list of headers that are safe to expose
            .expose_headers(&[header::AUTHORIZATION])
            // set preflight cache TTL
            .max_age(3600)
    }
}